﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;
using ReactiveUI;
using Product_1.ViewModels;
using System.Collections.ObjectModel;
using Product_1.ServiceReference1;

namespace Product_1.Views
{
    /// <summary>
    /// Interaction logic for Product_1_View.xaml
    /// </summary>
    public partial class Product_1_View : UserControl, IInputView, IViewFor<Product_1_ViewModel>
    {
        ServiceReference1.Container context = new ServiceReference1.Container(new Uri("http://localhost:1179/odata"));
        private InputPresenter _presenter;
        private readonly IUnityContainer container;
        private readonly IRegionManager rManager;


        public Product_1_View()
        {
            InitializeComponent();

            ViewModel = new Product_1_ViewModel();

            //this.Bind(ViewModel, vm => vm.Region1, v => v.BacchusListView2.DataContext);

            //this.BindCommand(ViewModel, vm => vm.Initialize, v => v.Computed1);

            this.BacchusListView.ItemsSource = (IEnumerable)context.Bacchus;

            this.materialsListView.ItemsSource = (IEnumerable)from kkk in context.Materials
                                                              where kkk.Pro_Id == 1
                                                              select kkk;
            
            this.materialsListView2.ItemsSource = (IEnumerable)from kkk in context.Materials
                                                               where kkk.Pro_Id != 1
                                                               select kkk;

            


            this.LotNumber.ItemsSource = from kkk in context.LotNumbers
                                         where kkk.Pro_Id == 1
                                         select new
                                         {
                                             PM_LotNumber = kkk.Lot_LotNumber
                                         };
        }

        public Product_1_View(InputPresenter presenter, IUnityContainer c, IRegionManager r) : this()
        {
            _presenter = presenter;
            _presenter.View = this;

            container = c;
            rManager = r;

            //Result2(this, null);
        }



        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.BacchusListView2.ItemsSource = from kkk in context.Bacchus
                                               select new
                                               {
                                                   Bac_Name = kkk.Bac_Name,
                                                   Bac_Quantity = kkk.Bac_Quantity * (Convert.ToInt32(this.Product_Quantity.Text))
                                               };
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            Uri viewNav = new Uri("Product_2_View", UriKind.Relative);
            rManager.RequestNavigate(RegionNames.MainContentRegion, viewNav);

            Result(this, null);


        }
      

        public Product_1_ViewModel ViewModel { get; set; }       
        object IViewFor.ViewModel
        {
            get
            {
                return ViewModel;
            }

            set
            {
                ViewModel = value as Product_1_ViewModel;
            }
        }

        public string Number
        {
            get
            {
                return this.LotNumber.Text.ToString();
            }
        }

        public string Year
        {
            get
            {
                return this.YearCbx.Text.ToString();
            }
        }

        public string Month
        {
            get
            {
                return this.MonthCbx.Text.ToString();
            }
        }

        public string Day
        {
            get
            {
                return this.DayCbx.Text.ToString();
            }
        }

        public string Quantity
        {
            get
            {
                return this.Product_Quantity.Text.ToString();
            }
        }

        public event EventHandler Result = delegate { };

        public event EventHandler Result2 = delegate { };

     
    }
}
